//2391.收集垃圾的最少总时间
//https://leetcode.cn/problems/minimum-amount-of-time-to-collect-garbage
class Solution {
public:
    int garbageCollection(vector<string>& garbage, vector<int>& travel) {
        unordered_map<char,int> m;//M P G字母 出现的最后时间
        int n = garbage.size();
        int ret = 0;
        int cur_tim = 0;
        for(int i = 0;i<n;++i)
        {
            ret += garbage[i].size();
            if(i > 0) cur_tim += travel[i-1]; //更新到达当前位置的时间
            for(char& c:garbage[i]) m[c] = cur_tim; //更新每个垃圾需要到达房子的最长时间
        }
        ret += m['M'] + m['P'] + m['G'];
        return ret;
    }
};